<?php
	include 'configuration.php';
	
	function download_friends($id)
	{
		mysql_select_db('facebook') or die('Could not select database');
		
		$query = "select access_token from users where id=$id";
		$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	
		$row = mysql_fetch_array($result, MYSQL_NUM);
		$token = $row[0];
		
		$friends_ids = json_decode(file_get_contents("https://graph.facebook.com/me/friends?access_token=$token&fields=id"));
		
		$friend_string = '';
		foreach($friends_ids->{'data'} as $friend_id)
		{
			$friend_string = $friend_string . $friend_id->{'id'};
			if (mysql_num_rows(mysql_query("SELECT id1 FROM friends WHERE id1 = '$id' and id2 = '$friend_id->{'id'}'")))
			{
				echo "$friend_id->{'id'} jest";
			}
			else
			{
				mysql_query("SELECT id1 FROM friends WHERE id1 = '$id' and id2 = '$friend_id->{'id'}'")
			}
		}
		$friends_hash = md5($friend_string);
	}
?>